import { FProxy } from "../../Framework/Support/FProxy";
import { Client } from "../../Framework/Network/Socket/Client";
import { ClientManager } from "../../Framework/Managers/ClientManager";
import { ClientName } from "../../Framework/Enums/ClientName";
import { ReceiveHandler } from "../../Framework/Network/Socket/ReceiveHandler";
import { IClientMessage } from "../../Framework/Interfaces/Sockets/IClientMessage";
import { EventManager } from "../../Framework/Managers/EventManager";
import { GameEvent } from "../../Framework/Event/GameEvent";
import { GameCommond } from "../Command/GameCommond";

export const CommonCmdId = {
    Login:"login",
    Error:"Error",
    GameQPMJ : "qpmj",
}


export default class CommonID extends FProxy {
    protected initClient(): Client {
        return ClientManager.GetClientByName(ClientName.GAME_CLIENT)
    }

    protected initHandlers() {
        super.initHandlers()
        this.client.addHandler(CommonCmdId.Login,new Login)
        this.client.addHandler(CommonCmdId.Error,new Error)
        this.client.addHandler(CommonCmdId.GameQPMJ,new GameQPMJ)
    }
}


class Login extends ReceiveHandler {
    public onDeal(client: Client, msg: IClientMessage) {
        EventManager.dispatchEventWith(GameEvent.ON_LOGIN_MSGHANDLER, msg.content)
    }
}

class Error extends ReceiveHandler {
    public onDeal(client: Client, msg: IClientMessage) {
        EventManager.dispatchEventWith(GameEvent.ON_ERROR_MSG, msg.content)
    }
}

class GameQPMJ extends ReceiveHandler {
    public onDeal(client: Client, msg: IClientMessage) {
        switch(msg.content.action) {
            case GameCommond.Game_CreaterDesk: case GameCommond.Game_JoinDesk:
                EventManager.dispatchEventWith(GameEvent.ON_GAME_QPMJ_CREATERSUCCESS, msg.content)
                //EventManager.dispatchEventWith(GameEvent.ON_GAME_QPMJ_JOINDESKSUCCESS, msg.content)
            break;
            default:
                EventManager.dispatchEventWith(GameEvent.ON_GAME_QPMJ_HANDLE, msg.content)
        }
    }
}
